package  com.infore.dataReceiving.util;



public class CRCCheck {
	public static String crc16(String src, int len) {
		int crc = 0x0000FFFF;
		short tc;
		char sbit;
		for (int i = 0; i < len; i++) {
			tc = (short) (crc >>> 8);
			crc = ((tc ^ src.charAt(i)) & 0x00FF);
			for (int r = 0; r < 8; r++) {
				sbit = (char) (crc & 0x01);
				crc >>>= 1; 
				if (sbit != 0)
					crc = (crc ^ 0xA001) & 0x0000FFFF;
			}
		}
		String str=Integer.toHexString(crc);
		if(str.length()==3){
			return "0"+str.toUpperCase();
		}else if(str.length()==2){
			return "00"+str.toUpperCase();
		}else if(str.length()==1){
			return "000"+str.toUpperCase();
		}
		return str.toUpperCase();
	}
	

	
	
}
